// 常规登录方法
const state = {
  token: '',
}

const mutations = {
  // 设置token
  SET_TOKEN: (state, token) => {
    state.token = token
  },
  // 删除token
  REMOVE_TOKEN: (state) => {
    state.token = ''
  },
}

const actions = {
  // 设置token
  async login({ commit }, form) {
    console.log(form);
      const { name, psw } = form
      const token = `${name}-${psw}`
      commit('SET_TOKEN', token)
      localStorage.setItem('token', token)
      return {
        code: 200,
        msg: '登录成功',
        data: {
          token,
        }
      }
  },
}

export default {
  state,
  mutations,
  actions,
  namespaced: true,
}
